import 'package:bot_toast/bot_toast.dart';
import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:simu_studio/app/services/influx_db_client_service.dart';
import 'package:simu_studio/app/services/mqtt_client_service.dart';
import 'package:simu_studio/generated/locales.g.dart';
import 'package:window_manager/window_manager.dart';

import 'app/routes/app_pages.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  if (GetPlatform.isDesktop) {
    await windowManager.ensureInitialized();

    windowManager.waitUntilReadyToShow().then((_) async {
      await windowManager.setTitle("Simu Studio");
      await windowManager.setTitleBarStyle(TitleBarStyle.normal);
      await windowManager.setBackgroundColor(Colors.white);
      await windowManager.setSize(const Size(1400, 950));
      await windowManager.setMinimumSize(const Size(750, 500));
      await windowManager.center();
      await windowManager.show();
      await windowManager.setSkipTaskbar(false);
    });
  }

  /// 缓存初始化
  await GetStorage.init();
  Get.put(MqttClientService());
  Get.put(InfluxDBClientService());

  runApp(
    fluent.FluentApp(
      debugShowCheckedModeBanner: false,
      theme: fluent.FluentThemeData(
        brightness: fluent.Brightness.light,
        accentColor: fluent.Colors.blue,
        focusTheme: const fluent.FocusThemeData(
          glowFactor: 2.0,
        ),
      ),
      home: GetMaterialApp(
        debugShowCheckedModeBanner: false,
        builder: BotToastInit(),
        title: "ApplicationName".tr,
        initialRoute: AppPages.INITIAL,
        getPages: AppPages.routes,
        translationsKeys: AppTranslation.translations,
        locale: const Locale('zh', 'CN'),
        navigatorObservers: [BotToastNavigatorObserver()],
      ),
    ),
  );
}
